package com.kaishengit.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kaishengit.entity.Admin;
import com.kaishengit.service.AdminService;
import com.kaishengit.util.web.ServletUtil;

public class AdminLogin extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		AdminService service = new AdminService();
		
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		
		Admin admin = service.login(username, password,ServletUtil.getIp(request));
		if(admin != null) {
			ServletUtil.setSessionAttirbute(request,"curr_admin",admin);
			ServletUtil.redirect(response, "/admin/home.jspx");
		} else {
			ServletUtil.redirect(response,"/admin/index.jspx?state=10001");
		}
		
	}

}
